package net.lab1024.smartadmin.module.business.torqueConverterLambda.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.dao.TorqueConverterLambdaDao;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.dto.TorqueConverterLambdaAddDTO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.dto.TorqueConverterLambdaQueryDTO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.dto.TorqueConverterLambdaUpdateDTO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.entity.TorqueConverterLambdaEntity;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.vo.TorqueConverterLambdaExcelVO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.vo.TorqueConverterLambdaVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 变矩器λ曲线 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 变矩器λ曲线
 * @copyright (c)  变矩器λ曲线Inc. All rights reserved.
 * @date 2021-11-13 15:05:32
 * @since JDK1.8
 */
@Service
public class TorqueConverterLambdaService {

    @Autowired
    private TorqueConverterLambdaDao torqueConverterLambdaDao;

    /**
     * 根据id查询
     */
    public TorqueConverterLambdaEntity getById(Long id){
        return  torqueConverterLambdaDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wuhq
     * @date 2021-11-13 15:05:32
     */
    public ResponseDTO<PageResultDTO<TorqueConverterLambdaVO>> queryByPage(TorqueConverterLambdaQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<TorqueConverterLambdaVO> voList = torqueConverterLambdaDao.queryByPage(page, queryDTO);
        PageResultDTO<TorqueConverterLambdaVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2021-11-13 15:05:32
     */
    public ResponseDTO<String> add(TorqueConverterLambdaAddDTO addDTO) {
        TorqueConverterLambdaEntity entity = SmartBeanUtil.copy(addDTO, TorqueConverterLambdaEntity.class);
        torqueConverterLambdaDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2021-11-13 15:05:32
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(TorqueConverterLambdaUpdateDTO updateDTO) {
        TorqueConverterLambdaEntity entity = SmartBeanUtil.copy(updateDTO, TorqueConverterLambdaEntity.class);
        torqueConverterLambdaDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2021-11-13 15:05:32
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        torqueConverterLambdaDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2021-11-13 15:05:32
     */
    public List<TorqueConverterLambdaExcelVO> queryAllExportData(TorqueConverterLambdaQueryDTO queryDTO) {
        return torqueConverterLambdaDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2021-11-13 15:05:32
     */
    public List<TorqueConverterLambdaExcelVO> queryBatchExportData(List<Long> idList) {
        return torqueConverterLambdaDao.queryBatchExportData(idList);
    }

    public TorqueConverterLambdaEntity getByTorqueConvertId(Long torqueConvertId) {
        LambdaQueryWrapper<TorqueConverterLambdaEntity> queryWrapper = new LambdaQueryWrapper<TorqueConverterLambdaEntity>();
        queryWrapper.eq(TorqueConverterLambdaEntity::getTorqueConvertId, torqueConvertId);
        return torqueConverterLambdaDao.selectOne(queryWrapper);

    }

    public void delByTorqueConvertId(Long torqueConvertId) {
        LambdaQueryWrapper<TorqueConverterLambdaEntity> queryWrapper = new LambdaQueryWrapper<TorqueConverterLambdaEntity>();
        queryWrapper.eq(TorqueConverterLambdaEntity::getTorqueConvertId, torqueConvertId);
        torqueConverterLambdaDao.delete(queryWrapper);
    }
}
